package com.hyd.springboot.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * AJAX请求跨域
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") //添加映射路径
                .allowedOrigins("*") //放行哪些原始域
                .allowCredentials(true) //是否发送Cookie信息
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")// 放行哪些原始域(请求方式)
                .maxAge(3600)
                .allowedHeaders("*");//放行哪些原始域(头部信息)
    }
}
